﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Web.UI.WebControls;

namespace Fish_Atlantis
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        static public string username = "";
        public string type;
        DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)//登录时保存在Session的值 
            {
                Response.Write("<script language='javascript'>alert('请登录后再操作！');window.location.href='Login.aspx' ;</script>");
           //     Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('请登录后再操作！！');location.href='/Account/Login.aspx';</script>");
            }
            else
            {
                username = Session["UserName"].ToString();
                type = Session["User_Type"].ToString();
            }
        }
        protected void btn_sub_Click(object sender, EventArgs e)
        {
            string str = "select * from Users where UserName='" + username + "' and PassWord='" + Text1.Value.ToString() + "'";

            ds = Helper.GetDataSet(str, "Users");


            if (ds.Tables[0].Rows.Count <= 0)
            {

                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('密码错误');</script>");
                return;
            }
            else
            {
                str = "UPDATE Users SET Password='"+Text2.Value.ToString()+"' WHERE UserID="+ds.Tables[0].Rows[0]["UserID"].ToString();
                if(Helper.ExecSQL(str))
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('修改成功');location.href='/Default.aspx';</script>");
                else
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('修改失败');location.href='/Default.aspx';</script>");
            }
        }
    }
}